package com.young.manager.controller;

import com.young.common.interf.IBaseController;
import com.young.common.model.ResultData;
import com.young.manager.model.SysRole;
import com.young.manager.service.SysRoleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RequestMapping("sysRole")
@RestController
@Slf4j
@RequiredArgsConstructor
public class SysRoleController implements IBaseController {

    private final SysRoleService sysRoleService;

    @GetMapping
    ResultData<?> queryList(@RequestParam(required = false) String name, @RequestParam(required = false) Integer pageNum, @RequestParam(required = false) Integer pageSize) {
        pageNum = null == pageNum ? DEFAULT_PAG_ENUM : pageNum;
        pageSize = null == pageSize ? DEFAULT_PAGE_SIZE : pageSize;
        return success(sysRoleService.queryList(name, pageNum, pageSize));
    }

    @PostMapping("insert")
    ResultData<?> insertSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.insertSysRole(sysRole);
        return success();
    }

    @PostMapping("update")
    ResultData<?> updateSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.updateSysRole(sysRole);
        return success();
    }

    @PostMapping("delete")
    ResultData<?> deleteSysRole(@RequestParam Long id) {
        sysRoleService.deleteSysRole(id);
        return success();
    }

}
